#include "mytype.h"
#include "appcfg.h"

/*******************************************************************************
* @brief  par struct define
*******************************************************************************/
#ifndef PAR_STR_DEFED
typedef const struct
{
	uint16_t attr;
	int16_t min;
	int16_t max;
	int16_t init;
	const char *name;
} par_attr_type;

#define PAR_STR_DEFED 1
#endif

/*******************************************************************************
* @brief  par creat
*******************************************************************************/
#ifdef PAR_ARRT_CREAT
#define par_make(name, attr, min, max, init, en, cn, discribe) \
	{attr, min, max, init, en},
#elif defined PAR_LIST_CREAT
#define par_make(name, attr, min, max, init, en, cn, discribe) \
	u16_tt name;

#else
#define par_make(...)
#endif

/*******************************************************************************
* @brief  par list define
*******************************************************************************/
#ifdef PAR_ARRT_CREAT
const par_attr_type par_attr_tab[] = {
#endif

#ifdef PAR_LIST_CREAT
typedef struct
{
#endif

	par_make(head, PAR_ATTR_NONE, 0, 0, 0, "head", "cn", "表头")
	par_make(ver_id, PAR_ATTR_NONE, VERSION_ID, VERSION_ID, VERSION_ID, "vid", "VID", "表ID")
	
	par_make(mark_lck, PAR_ATTR_RST, INT16_MIN, INT16_MAX, 0, "mck", "标定解锁", "标定")
	par_make(mark1_low, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "1L", "标定1L", "标定")
	par_make(mark1_mid, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "1N", "标定1M", "标定")
	par_make(mark1_high, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "1H", "标定1H", "标定")
	par_make(mark2_low, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "2L", "标定1L", "标定")
	par_make(mark2_mid, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "2N", "标定1M", "标定")
	par_make(mark2_high, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "2H", "标定1H", "标定")
	par_make(mark3_low, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "3L", "标定1L", "标定")
	par_make(mark3_mid, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "3N", "标定1M", "标定")
	par_make(mark3_high, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "3H", "标定1H", "标定")
	par_make(mark4_low, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "4L", "标定1L", "标定")
	par_make(mark4_mid, PAR_ATTR_NINIT, INT16_MIN, INT16_MAX, 0, "4N", "标定1M", "标定")
	par_make(mark4_high, PAR_ATTR_NINIT | PAR_ATTR_END, INT16_MIN, INT16_MAX, 0, "4H", "标定1H", "标定")
	
	// 数据格式：
	// 标记 信息 信息 校验
	// a组b组同时存储，a组校验失败时验证b组，都失败时初始化为最小授权
	par_make(lic_key1, PAR_ATTR_KEEP, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "授权KEY")
	par_make(lic_key2, PAR_ATTR_KEEP, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "授权KEY-")
	par_make(lic_key3, PAR_ATTR_KEEP, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "授权KEY-")
	par_make(lic_key4, PAR_ATTR_KEEP, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "授权KEY-")
	par_make(lic_inf1, PAR_ATTR_RST, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "授权密文-")
	par_make(lic_inf2, PAR_ATTR_RST, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "授权密文-")
	par_make(lic_inf3, PAR_ATTR_RST, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "授权密文-")
	par_make(lic_inf4, PAR_ATTR_RST, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "授权密文-")
	
	par_make(loop_cnt, PAR_ATTR_KEEP | PAR_ATTR_32BIT, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "运行次数")
	par_make(loop_cnt_h, PAR_ATTR_KEEP | PAR_ATTR_32BIT, INT16_MIN, INT16_MAX, 0, "cnt", "cn", "运行次数")
		
	par_make(reset_req, PAR_ATTR_NONE, INT16_MIN, INT16_MAX, 0, "rst", "cn", "复位")
	par_make(lic_req, PAR_ATTR_RST | PAR_ATTR_END, 0, 9999, 0, "lic", "cn", "授权开启")	
	par_make(dbg_en, PAR_ATTR_RST, 0, 9999, 0, "dbg", "dbg", "调试")	
	par_make(dbg_out, PAR_ATTR_RST, 0, 9999, 0, "out", "out", "调试")
	par_make(dbg_in, PAR_ATTR_RST, 0, 9999, 0, "in", "in", "调试")
	par_make(dbg_end, PAR_ATTR_END, 0, 9999, 0, "end", "end", "调试")
	
	par_make(com1_id, PAR_ATTR_NONE, 1, 254, 2, "Id", "Id", "COM")	
	par_make(com1_baud, PAR_ATTR_NONE, 12, 1152, 192, "bA", "bA", "COM")
	par_make(com1_fo, PAR_ATTR_NONE, 0, 7, 2, "Fo", "Fo", "COM")
	par_make(com2_id, PAR_ATTR_NONE, 1, 254, 2, "Id", "Id", "COM")	
	par_make(com2_baud, PAR_ATTR_NONE, 12, 1152, 192, "bA", "bA", "COM")
	par_make(com2_fo, PAR_ATTR_NONE, 0, 7, 2, "Fo", "Fo", "COM")
	
	par_make(pt, PAR_ATTR_NONE, 0, 9999, 0, "Pt", "Pt", "TM")
	par_make(ut, PAR_ATTR_NONE, 0, 9999, 0, "Pt", "Pt", "TM")
	par_make(rtc_year, PAR_ATTR_NONE, 2000, 2099, 2022, "year", "year", "TM")
	par_make(rtc_mon, PAR_ATTR_NONE, 1, 12, 6, "year", "year", "TM")
	par_make(rtc_day, PAR_ATTR_NONE, 1, 31, 15, "mon", "mon", "TM")
	par_make(rtc_hour, PAR_ATTR_NONE, 0, 23, 12, "hour", "hour", "TM")
	par_make(rtc_min, PAR_ATTR_NONE, 0, 59, 30, "min", "min", "TM")
	par_make(rtc_update, PAR_ATTR_RST | PAR_ATTR_END, 0, 1, 0, "on", "on", "TM")
	
	par_make(unlock_code, PAR_ATTR_NONE, 0, 9999, 0, "unlock", "cn", "密码")
	par_make(prog_mode, PAR_ATTR_NONE, 0, 2, 1, "prog mode", "cn", "程序模式")
	par_make(power_mode, PAR_ATTR_NONE, 0, 2, 0, "power mode", "cn", "上电模式")

	par_make(GP30_temp, PAR_ATTR_POINT(2), -10000, 10000, 0, "GP30.TEMP", "cn", "温度校正")

	par_make(GP30_Q1, PAR_ATTR_32BIT|PAR_ATTR_POINT(3), 0, 0, 0, "GP30.Q1", "cn", "GP30.Q1")
	par_make(_____Q1, PAR_ATTR_32BIT|PAR_ATTR_POINT(3), -100, 100, 0, "GP30.Q1", "cn", "GP30.Q1")

	par_make(GP30_Q2, PAR_ATTR_32BIT|PAR_ATTR_POINT(3), 0, 0, 0, "GP30.Q2", "cn", "GP30.Q2")
	par_make(_____Q2, PAR_ATTR_32BIT|PAR_ATTR_POINT(3), -100, 100, 0, "GP30.Q2", "cn", "GP30.Q2")

	par_make(GP30_Q3, PAR_ATTR_32BIT|PAR_ATTR_POINT(3), 0, 0, 0, "GP30.Q3", "cn", "GP30.Q3")
	par_make(_____Q3, PAR_ATTR_32BIT|PAR_ATTR_POINT(3), -100, 100, 0, "GP30.Q3", "cn", "GP30.Q3")

	par_make(GP30_DEV_ID, PAR_ATTR_32BIT, 0, 0, 0, "GP30.DEV.ID", "cn", "GP30 设备ID")
	par_make(_____DEV_ID, PAR_ATTR_32BIT, 0, 9999, 0, "GP30.DEV.ID", "cn", "GP30 设备ID")

	par_make(GP30_FAC_ID, PAR_ATTR_32BIT, 0, 0, 0, "GP30.FAC.ID", "cn", "GP30 工厂ID")
	par_make(_____FAC_ID, PAR_ATTR_32BIT, 0, 9999, 0, "GP30.FAC.ID", "cn", "GP30 工厂ID")

	par_make(GP30_YEAR, PAR_ATTR_NONE, 2000, 2099, 2023, "GP30.YEAR", "cn", "GP30")
	par_make(GP30_MON, PAR_ATTR_NONE, 1, 12, 6, "GP30.MON", "cn", "GP30")
	par_make(GP30_DAY, PAR_ATTR_NONE, 1, 31, 15, "GP30.DAY", "cn", "GP30")
	par_make(GP30_HOUR, PAR_ATTR_NONE, 0, 23, 12, "GP30.HOUR", "cn", "GP30")
	par_make(GP30_MIN, PAR_ATTR_NONE, 0, 59, 30, "GP30.MIN", "cn", "GP30")
	par_make(GP30_SEC, PAR_ATTR_NONE, 0, 59, 30, "GP30.SEC", "cn", "GP30")

	par_make(time_unit, PAR_ATTR_NONE, 0, 2, 0, "time unit", "cn", "时间单位")
	par_make(time_mode, PAR_ATTR_NONE, 0, 1, 1, "time mode", "cn", "计时方式")
	par_make(cf, PAR_ATTR_NONE, 0, 1, 0, "temp unit", "cn", "温度单位")	
	
	par_make(pwm_period, PAR_ATTR_32BIT, 0, 0, 30000, "period", "cn", "PWM")
	par_make(pwm_period_hw, PAR_ATTR_32BIT | PAR_ATTR_WHIGH, 0, 6, 0, "periodh", "cn", "PWM")
	par_make(pwm_duty, PAR_ATTR_32BIT, 0, 0, 1000, "duty", "cn", "PWM")
	par_make(pwm_duty_hw, PAR_ATTR_32BIT | PAR_ATTR_WHIGH, 0, 6, 0, "dutyh", "cn", "PWM")

	par_make(pb1, PAR_ATTR_NFUN , -1999, 9999, 0, "pb1", "cn", "pbpk")
	par_make(pk1, PAR_ATTR_POINT(1), -1999, 9999, 0, "pk1", "cn", "pbpk")
	par_make(pb2, PAR_ATTR_NFUN , -1999, 9999, 0, "pb2", "cn", "pbpk")
	par_make(pk2, PAR_ATTR_POINT(1), -1999, 9999, 0, "pk2", "cn", "pbpk")
	par_make(pb3, PAR_ATTR_NFUN , -1999, 9999, 0, "pb3", "cn", "pbpk")
	par_make(pk3, PAR_ATTR_POINT(1), -1999, 9999, 0, "pk3", "cn", "pbpk")
	par_make(pb4, PAR_ATTR_NFUN , -1999, 9999, 0, "pb4", "cn", "pbpk")
	par_make(pk4, PAR_ATTR_POINT(1), -1999, 9999, 0, "pk4", "cn", "pbpk")
	par_make(pb5, PAR_ATTR_NFUN , -1999, 9999, 0, "pb5", "cn", "pbpk")
	par_make(pk5, PAR_ATTR_POINT(1), -1999, 9999, 0, "pk5", "cn", "pbpk")
	par_make(pb6, PAR_ATTR_NFUN , -1999, 9999, 0, "pb6", "cn", "pbpk")
	par_make(pk6, PAR_ATTR_POINT(1), -1999, 9999, 0, "pk6", "cn", "pbpk")
	par_make(pb7, PAR_ATTR_NFUN , -1999, 9999, 0, "pb7", "cn", "pbpk")
	par_make(pk7, PAR_ATTR_POINT(1), -1999, 9999, 0, "pk7", "cn", "pbpk")
	par_make(pb8, PAR_ATTR_NFUN , -1999, 9999, 0, "pb8", "cn", "pbpk")
	par_make(pk8, PAR_ATTR_POINT(1), -1999, 9999, 0, "pk8", "cn", "pbpk")
	
	par_make(tal, PAR_ATTR_POINT(1), 0, 9999, 0, "al", "cn", "alr")
	par_make(tah, PAR_ATTR_POINT(1), 0, 9999, 50, "ah", "cn", "alr")
	par_make(tapl, PAR_ATTR_POINT(1), -600, 9999, 3000, "ap", "cn", "alr")
	par_make(taph, PAR_ATTR_POINT(1), -600, 9999, -600, "ap", "cn", "alr")
	par_make(tapt, PAR_ATTR_NONE, 0, 9999, 60, "apt", "cn", "alr")
	par_make(tpid_p1, PAR_ATTR_POINT(1), 1, 9999, 50, "p1", "cn", "PID")
	par_make(tpid_i1, PAR_ATTR_NONE, 0, 9999, 240, "i1", "cn", "PID")
	par_make(tpid_d1, PAR_ATTR_NONE, 0, 9999, 180, "d1", "cn", "PID")
	par_make(tpid_ar1, PAR_ATTR_NONE, 1, 100, 100, "ar1", "cn", "PID")
	par_make(tpid_p2, PAR_ATTR_POINT(1), 1, 9999, 50, "p2", "cn", "PID")
	par_make(tpid_i2, PAR_ATTR_NONE, 0, 9999, 240, "i2", "cn", "PID")
	par_make(tpid_d2, PAR_ATTR_NONE, 0, 9999, 180, "d2", "cn", "PID")
	par_make(tpid_ar2, PAR_ATTR_NONE, 1, 100, 100, "ar2", "cn", "PID")
	par_make(tpid_t, PAR_ATTR_NONE, 1, 120, 3, "t", "cn", "PID")
	par_make(hpid_p, PAR_ATTR_POINT(1), 0, 9999, 50, "hp", "cn", "PID")
	par_make(hpid_i, PAR_ATTR_NONE, 0, 9999, 50, "hi", "cn", "PID")
	par_make(hpid_d, PAR_ATTR_NONE, 0, 9999, 50, "hd", "cn", "PID")
	par_make(hpid_ar, PAR_ATTR_NONE, 0, 9999, 50, "har", "cn", "PID")
	par_make(hpid_t, PAR_ATTR_NONE, 1, 120, 3, "ht", "cn", "PID")
	
	par_make(temp_lmt_low, PAR_ATTR_POINT(1), -400, 2000, -200, "lmt low", "cn", "温度下限")
	par_make(temp_lmt_high, PAR_ATTR_POINT(1), -400, 2000, 1800, "lmt high", "cn", "温度上限")
	par_make(at, PAR_ATTR_RST, 0, 2, 0, "at", "cn", "温度单位")
	par_make(cnt, PAR_ATTR_END | PAR_ATTR_KEEP, 0, 1, 0, "cnt", "cn", "温度单位")

	par_make(sp, PAR_ATTR_POINT(1), 0, 19, 500, "sp", "cn", "设定温度")
	par_make(st, PAR_ATTR_NONE, 0, 19, 60, "sp", "cn", "设定时间")
	par_make(ot, PAR_ATTR_NONE, 0, 19, 100, "sp", "cn", "功率限制")
	par_make(end, PAR_ATTR_NONE, 0, 20, 0, "head", "cn", "表尾")
	par_make(resver1, PAR_ATTR_NONE, 0, 20, 0, "res", "cn", "end")
	par_make(resver2, PAR_ATTR_NONE, 0, 20, 0, "res", "cn", "end")

#ifdef PAR_ARRT_CREAT
};
#endif

#ifdef PAR_LIST_CREAT
} par_tab_type;
#endif



/*******************************************************************************
* @brief  group par creat
*******************************************************************************/

/*******************************************************************************
* @brief  group par list define, 如果每组参数属性相同，一组属性即可
* @brief  各组 attr 域的U32标记必须相同
*******************************************************************************/
#ifdef PAR_ARRT_CREAT
const par_attr_type gp_par_attr_tab[][12] = {
	{
#endif

#ifdef PAR_LIST_CREAT
	typedef struct
	{
#endif

	par_make(base,		PAR_ATTR_NONE,	0,		8,		0,		"head",	"cn", "表头")
	par_make(sub_num,	PAR_ATTR_NONE,	0,		20,		0,		"sub",	"cn", "表头")
	par_make(stri_temp,	PAR_ATTR_NONE,	1050,	1340,	1210,	"sp",	"cn", "表头")
	par_make(stri_time,	PAR_ATTR_NONE,	1,		6000,	5,		"st",	"cn", "表头")
	par_make(airo_temp,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(open_time,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(aux_temp,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(aux_time,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(cool_en,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(f0val_en,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(f0val_set, PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(end,		PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")

#ifdef PAR_LIST_CREAT
	} gp_par_def_type;
#endif

#ifdef PAR_ARRT_CREAT
},
{
	par_make(base,		PAR_ATTR_NONE,	0,		8,		0,		"head",	"cn", "表头")
	par_make(sub_num,	PAR_ATTR_NONE,	0,		20,		0,		"sub",	"cn", "表头")
	par_make(stri_temp,	PAR_ATTR_NONE,	1050,	1340,	1210,	"sp",	"cn", "表头")
	par_make(stri_time,	PAR_ATTR_NONE,	1,		6000,	5,		"st",	"cn", "表头")
	par_make(airo_temp,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(open_time,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(aux_temp,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(aux_time,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(cool_en,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(f0val_en,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(f0val_set, PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(end,		PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
},
{
	par_make(base,		PAR_ATTR_NONE,	0,		8,		0,		"head",	"cn", "表头")
	par_make(sub_num,	PAR_ATTR_NONE,	0,		20,		0,		"sub",	"cn", "表头")
	par_make(stri_temp,	PAR_ATTR_NONE,	1050,	1340,	1210,	"sp",	"cn", "表头")
	par_make(stri_time,	PAR_ATTR_NONE,	1,		6000,	5,		"st",	"cn", "表头")
	par_make(airo_temp,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(open_time,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(aux_temp,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(aux_time,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(cool_en,	PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(f0val_en,	PAR_ATTR_NONE,	0, 		600,	60,		"wp",	"cn", "表头")
	par_make(f0val_set, PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
	par_make(end,		PAR_ATTR_NONE,	0, 		600,	24,		"wt",	"cn", "表头")
},
{0},
};
#endif

#ifdef par_make
#undef par_make
#endif
